package com.qf.simple;

import com.qf.util.ConnUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

public class Publisher {

    public static final String QUEUE_NAME = "hello1";

    @Test
    public void publish() throws Exception {
        //1. 获取连接对象
        Connection conn = ConnUtil.getConn();

        //2. 创建channel通道
        Channel channel = conn.createChannel();

        //3. 通过channel声名一个队列
        //  String queue(队列名称), boolean durable(队列是否持久化), boolean exclusive(是否排外),
        //  boolean autoDelete(队列没有消息是否自动删除), Map<String, Object> arguments(队列的其他属性)
        channel.queueDeclare(QUEUE_NAME,true,false,true,null);

        //4. 通过channel发送消息到队列中
//        String msg = "Hello World!!";
//        channel.basicPublish("",QUEUE_NAME,null,msg.getBytes());

        //5. 输出结果，释放资源
//        System.out.println(msg + "消息发送成功!!");
        channel.close();
        conn.close();
    }

}
